﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RainyPWS.Model;
using RainyPWS.Data;
using RainyPWS.Common;
using System.Data;
using System.Data.Common;

namespace RainyPWS.Business
{
    public class BUser
    {
        private static BUser _instance = null;

        public static BUser Instance
        {
            get
            {
                if (_instance == null)
                {
                    _instance = new BUser();
                }
                return _instance;
            }
        }

        public MUser GetUserByUserCode(string userCode)
        {
            string sql = "select * from TAdmin where UserCode=@UserCode";
            SqlDatabase db = new SqlDatabase(StaticVar.ConnectionString);
            DbCommand cmd = db.GetSqlStringCommand(sql);
            db.AddInParameter(cmd, "@UserCode", DbType.String, userCode);
            using (IDataReader rdr = db.ExecuteReader(cmd))
            {
                if (rdr.Read())
                {
                    return new MUser(rdr);
                }
                else
                {
                    return new MUser();
                }
            }
        }
    }
}
